<template>
    <div class="boxContentCss">
        <el-form ref="form" :model="form" label-position="right" label-width="auto">
            <EdCreateCard title="订单概要">
                <template #back>
                    <div class="createBack" @click="$utilsSet.goBack($router)" >
                        <svg-icon icon-class="back" /> 返回
                    </div>
                </template>
                <div class="zh_flex">
                    <div class="border-radius-top mainBackgroundColor width-80">
                        <el-row>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">订单编号：{{form.orderNo || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">创建时间：{{form.createTime || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">
                                订单状态：<span :class="['spanLabel spanLabelWidth marginRight8', 'spanLabelColor'+form.status]"></span>{{returnName(form.status, selectOrderStatus.options) || form.status || '-'}}
                            </el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">核销方式：{{returnName(form['verificationType'], selectVerifyMethod.options) || form['verificationType']  || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">客户姓名：{{form.buyerName || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">客户电话：{{form.buyerPhone || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">核销时间：{{form.verificationTime || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">核销人员：{{form.verificationName || '-'}}</el-col>
                        </el-row>
                        <!-- <el-row v-if="form.status==6">
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">退款申请时间：{{ form.refundData&&form.refundData.refundApplyTime || '-'}}</el-col>
                            <el-col :span="8" class="fontSize14 color085 marginBottom12 marginTop12">退款时间：{{ form.refundData&&form.refundData.refundTime || '-'}}</el-col>
                        </el-row> -->
                    </div>
                </div>
            </EdCreateCard>
            <EdCreateCard title="订单详情">
                <div class="zh_flex">
                    <div class="border-radius-top mainBackgroundColor width-80">
                        <el-row>
                            <el-table :data="form.items" class="table marginTop10 width-100">
                                <el-table-column v-if="$store.getters.type == 1" prop="productSource" label="来源">
                                    <template slot-scope="scope">
                                        <span>{{returnName(scope.row['productSource'], selectSource.options) || scope.row['productSource'] || '-'}}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column v-if="$store.getters.type == 2 || $store.getters.type == 3 || $store.getters.type == 5" prop="merchantName" label="店铺名称">
                                    <template slot-scope="scope">
                                        <span>{{ form.merchantName || '-'}}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="productName" label="商品名称" :formatter="formatter"></el-table-column>
                                <el-table-column prop="" label="商品图片">
                                    <template slot-scope="scope">
                                        <div style="display: flex" v-if="scope.row.skuPic">
                                            <el-image 
                                                :key="scope.row.skuPic"
                                                :src="scope.row.skuPic" 
                                                style="width: 100px; height: 100px;vertical-align: text-top;"
                                                :preview-src-list="[scope.row.skuPic]">
                                            </el-image>
                                        </div>
                                        <div v-else>-</div>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="moneySin" label="单价">
                                    <template slot-scope="scope">
                                        <div v-if="!scope.row['money'] && !scope.row['point']">
                                            -
                                        </div>
                                        <div v-else>
                                            <div v-if="scope.row['money'] && !scope.row['point']">{{ scope.row['money'] }}元</div>
                                            <div v-if="!scope.row['money'] && scope.row['point']">{{ scope.row['point'] }}积分</div>
                                            <div v-if="scope.row['money'] && scope.row['point']">{{ scope.row['money'] }}元+{{ scope.row['point'] }}积分</div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="itemCount" label="数量" :formatter="formatter"></el-table-column>
                                <el-table-column prop="" label="订单金额">
                                    <template slot-scope="scope">
                                        <div v-if="!scope.row['totalMoney'] && !scope.row['totalPoint']">
                                            -
                                        </div>
                                        <div v-else>
                                            <div v-if="scope.row['totalMoney'] && !scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元</div>
                                            <div v-if="!scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalPoint'] }}积分</div>
                                            <div v-if="scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元+{{ scope.row['totalPoint'] }}积分</div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column v-if="form.status==6 && form.refundData" prop="refundMoney" label="退款金额">
                                    <template slot-scope="scope">
                                        <div v-if="!scope.row['totalMoney'] && !scope.row['totalPoint']">
                                            -
                                        </div>
                                        <div v-else>
                                            <div v-if="scope.row['totalMoney'] && !scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元</div>
                                            <div v-if="!scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalPoint'] }}积分</div>
                                            <div v-if="scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元+{{ scope.row['totalPoint'] }}积分</div>
                                        </div>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-row>
                    </div>
                </div>
            </EdCreateCard>
            <EdCreateCard v-if="form.status==6 && form.refundData" title="退款审核">
            <!-- <EdCreateCard v-if="form.refundData" title="退款审核"> -->
                <div class="zh_flex">
                    <div class="border-radius-top mainBackgroundColor width-80">
                        <el-row >
                            <el-col :span="24" class="fontSize14 color085 marginBottom12 marginTop12">退款原因：{{form.refundData['refundMsg']||'-'}}</el-col>

                            <el-col :span="24" class="fontSize14 color085 marginBottom12 marginTop12" v-if="form.refundData.refundPics&&form.refundData.refundPics.length>0">退款凭证：
                                <el-image 
                                    v-for="item in form.refundData.refundPics&&form.refundData.refundPics"
                                    :key="item"
                                    :src="item" 
                                    style="width: 100px; height: 100px;vertical-align: text-top"
                                    :preview-src-list="form.refundData.refundPics">
                                </el-image>
                            </el-col>
                            <el-col :span="24" class="fontSize14 color085 marginBottom12 marginTop12" v-else>退款凭证：-</el-col>

                            <el-col :span="24" class="fontSize14 color085 marginBottom12 marginTop12">退款审核：
                                <el-button class="ed-table-bottom ed_2_border">通过</el-button>
                            </el-col>
                        </el-row>
                    </div>
                </div>
            </EdCreateCard>
        </el-form>
    </div>
</template>

<script>
    import EdCreateCard from 'src/components/EdCreateCard.vue'
    import {orderDetail} from "./api";
    import { defineComponent } from 'vue'
    import { getDictByCode } from "src/api/dictionaries";
    import { returnName } from "src/utils/common.js";
    export default defineComponent({
        name: "OrderDetails",
        components: { EdCreateCard},
        data(){
            return{
                form:{},
                selectSource:{
                    placeholder:"请选择来源",
                    options: []
                },
                selectVerifyMethod:{
                    placeholder:"请选择核销方式",
                    options: [],
                },
                selectOrderStatus:{  // 订单状态
                    placeholder:"请选择订单状态",
                    options: []
                },
            }
        },
        activated(){
            // 来源
            getDictByCode('product_source').then(res=>{
                this.selectSource.options = res.data.items;
            });
            // 核销方式
            getDictByCode('product_verify_method').then(res=>{
                this.selectVerifyMethod.options = res.data.items;
            });
            // 订单状态
            getDictByCode('order_status_type').then(res=>{
                this.selectOrderStatus.options = res.data.items;
            });
            this.orderDetail()
        },
        deactivated(){

        },
        methods:{
            orderDetail(){
                orderDetail({id:this.$route.query.id}).then(response => {
                    if(response.success == true) {
                        this.form = response.data;
                        // this.form.items.productPic = ['https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1657904400&t=a5420d6110e949d35855acdd28b6f6e4']
                        this.form.items = [].concat(response.data.items);
                    }
                })
            },
            returnName(val, options, value, label){
                return returnName(val, options, value, label)
            },
            formatter(row, column, cellValue, index){
                return cellValue || '-'
            }
        }
    })
</script>

<style scoped lang="scss">
    .spanLabel{
        width: 8px;height: 8px;
        border-radius: 50%;
        display: inline-block;vertical-align: 1px
    }
    .spanLabelWidth{
        width: 6px;height: 6px;
    }

    :deep .table{
        border-radius: 8px 8px 0 0;
        margin-bottom: 16px;
        // border: 1px solid #E4E7ED;
        thead tr th {
            background: #F4F4F4;
            color: #909399;
        }

        tbody tr {
            background: #FBFBFB;
            td {
                color: #606266;
            }
        }

        tbody tr:hover td{
            /* background-color: #FEF9F0; */
            background-color: #FEF9F0 !important;
        }
    }
    
    .titleTop{
        border: 1px solid rgba(0, 0, 0, 0.65);width: 14px;height: 14px;line-height: 14px;
        border-radius: 50%;font-size: 12px;text-align: center;display: inline-block;vertical-align: 1px;margin-left: 4px;
    }

    .titleTopBorderColor1{
        border-color: rgba(0, 0, 0, 0.65);
    }
    .titleTopBorderColor2{
        border-color: #FAAD14;
    }
    .titleTopBorderColor3{
        border-color: #52C41A;
    }
    .titleTopBorderColor4{
        border-color: #1890FF;
    }
    .titleTopBorderColor5{
        border-color: #B7B7B7;
    }
    .spanLabelColor10{
        background-color: #65A9A5 !important;
    }
    .spanLabelColor0{
        background-color: #65A9A5 !important;
    }
    .spanLabelColor9{
        background-color: #EED096 !important;
    }
    .spanLabelColor8{
        background-color: #414448 !important;
    }
    .spanLabelColor6{
        background-color: #EE7171 !important;
    }
    .spanLabelColor99{
        background-color: #EE7171 !important;
    }
</style>